﻿<!doctype html>
<html>
<head>
    <link href="css/base.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <script src="js/baiduTemplate.js"></script>
</head>
<body>

<article class="blogs">
    <h2 class="title_tj">
    <p>文章<span>推荐</span></p>
  </h2>
	<div class="newblog left">
        <!--左left开始-->
        <div id="result"></div>
        <script id="t:_1234-abcd-1" type="text/html">
            <%for(var i=0; i < list.length; i++){%>
                
            <%}%>
        </script>
        
          <!--分页开始-->
        <div class="page">
              
        </div>
        <!--分页结束-->
	</div>
</article>
<footer>
    <p class="ft-copyright">个人博客 Sunshine </p>
    <div id="tbox"> <a id="togbook" href=""></a> <a id="gotop" href="javascript:void(0)"></a></div>
</footer>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

<script>
    // $.get("http://localhost:8084/getChapterList", function(data) {
    //     console.log(data)
    //     var data={
    //         "title":'欢迎使用baiduTemplate',
    //         "list": data
    //     };
    //     var bt=baidu.template;
    //     var html=bt('t:_1234-abcd-1',data);
    //     document.getElementById('result').innerHTML=html;
    //     console.log(data);
    // })
    fetch("http://localhost:8084/getChapterList")
    .then(res => res.json())
    .then(res => {
        let myul = document.getElementById('result');
        for(let i = 0 ; i<res.length;i++){
            myul.innerHTML+=`<div class="oneblog">
                    <h2><a title="路·过-喜欢在路上" href="/">${res[i]["chapterName"]}</a></h2>
                    <figure><img src=${res[i]["imgPath"] } border='0' width='120' height='120' alt='路·过-喜欢在路上'></figure>
                    <ul class="nlist">
                        <p>${res[i]["chapterDes"].slice(0,100)}...</p>
                        <a title="路·过-喜欢在路上" href="##" target="_blank" class="readmore" onclick="showDetail(event, ${res[i]["id"] })">阅读全文>></a>
                    </ul>
                    <p class="dateview">
                        <span>发布时间：${res[i]["publishTimer"]}</span>
                        <span>作者：${res[i]["author"]}</span>
                        <span>分类：[<a href="/">${res[i]["class"]}</a>]</span>
                        <span class="nl">浏览（${res[i]["views"]})</span>
                        <span class="n2">评论（<a href="/">0</a>）</span>
                        <div class="line"></div>
                    </p>
                </div>`
        }
    })

    function showDetail(e, chapterId) {
        e.preventDefault();
        console.log(chapterId);
        window.location = "http://localhost:8084/detail?chapterId=" + chapterId;
    }
</script>
</html>